$(function () {
    $('#submit_login').click(function () {
        var userName = $('#userName').val();
        var code = $('#code').val();
        var codeValues = $("#codeValues").val();
        if(userName == null || userName == ""){
            alert("请输入手机号！");
            return false
        }
        if(code==null ||code==""){
            alert("请输入验证码！");
            return;
        }
        if(code !=codeValues ){
            alert("验证码错误！");
            return;
        }
        $.ajax({
            url: Feng.ctxPath + "/integralMallWeixin/loginTo",
            type: "post",
            data: {
                "userName": userName,
            },
            success: function (data) {
                if(data==3){
                    alert("您未到过钛植!");
                    window.location.href = Feng.ctxPath + '/integralMallWeixin/logincus';
                }else if(data==2){
                    window.location.href = Feng.ctxPath + '/integralMallWeixin/logincus';
                }else{
                    if($("#tabId").val()==1){
                        window.location.href = Feng.ctxPath + '/integralMallWeixin/personalCenter';
                    } else {
                        window.location.href = Feng.ctxPath + '/integralMallWeixin/scoreShopping';
                    }
                }
            },
            error: function (data) {
                alert('权限被限制，请联系管理员!');
            }
        });
    });

    var viewHeight = window.innerHeight;
    $("input").focus(function(){
        var signInTop = $(".signIn").offset().top;
        var btnTop = $(".btnBox").offset().top;
        $(".Resetbody,html").css({"height":viewHeight});
        $(".signIn").css('top',signInTop);
        $(".btnBox").css('top',btnTop);
    });
});

var countdown = 60;
function getLoginCode() {
    var customerPhone = $("#userName").val();
    if(customerPhone == "" || customerPhone == undefined){
        alert("请输入手机号！");
        return false
    }
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/getCode",
        type: "post",
        data: {
            "customerPhone": customerPhone
        },
        success: function (data) {
            Feng.success("发送成功！");
            settime($("#numbtn"));
            $("#codeValues").val(data.split(",")[0]);
        },
        error: function (data) {
            alert('系统错误，获取失败!');
        }
    })
}
function settime(obj) { //发送验证码倒计时
    if (countdown == 0) {
        obj.attr('disabled', false);
        obj.html("获取验证码");
        countdown = 60;
        return;
    } else {
        obj.attr('disabled', true);
        obj.html("重新发送(" + countdown + ")");
        countdown--;
    }

    setTimeout(function () {
        settime(obj)
    }, 1000)

}